/**
 * Copyright  2025, Hai Yue Xing He  ZHAO LIMIN
 *
 * @author          ZHAO LIMIN
 * @version         1.0.1
 * @since           2025-04
 * Color.ts         色彩
 */
import { Check } from './Check'
import { Frozen } from './Frozen'
import { defined } from './Defined'
import { HYXHMathUtil } from './HYXHMathUtil'
import { Cartesian4 } from './Cartesian4'
import { defaultValue } from './HYXHDefaultValue'
import { UNION_NUMBER_ARRAY } from './HDataType'

export interface IColor {
  red: number
  green: number
  blue: number
  alpha: number
}

export interface IColorIndex {
  [index: string]: Color
}

export class Color implements IColor {
  red: number
  green: number
  blue: number
  alpha: number
  constructor(red?: number, green?: number, blue?: number, alpha?: number) {
    /**
     * The red component.
     * @type {number}
     * @default 1.0
     */
    this.red = red ?? 1.0
    /**
     * The green component.
     * @type {number}
     * @default 1.0
     */
    this.green = green ?? 1.0
    /**
     * The blue component.
     * @type {number}
     * @default 1.0
     */
    this.blue = blue ?? 1.0
    /**
     * The alpha component.
     * @type {number}
     * @default 1.0
     */
    this.alpha = alpha ?? 1.0
  }
  /**
   * Creates a Color instance from a {@link Cartesian4}. <code>x</code>, <code>y</code>, <code>z</code>,
   * and <code>w</code> map to <code>red</code>, <code>green</code>, <code>blue</code>, and <code>alpha</code>, respectively.
   *
   * @param {Cartesian4} cartesian The source cartesian.
   * @param {Color} [result] The object onto which to store the result.
   * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
   */
  public static fromCartesian4(cartesian: Cartesian4, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('cartesian', cartesian)
    //>>includeEnd('debug');

    if (!defined(result)) {
      return new Color(cartesian.x, cartesian.y, cartesian.z, cartesian.w)
    }

    result.red = cartesian.x
    result.green = cartesian.y
    result.blue = cartesian.z
    result.alpha = cartesian.w
    return result
  }

  /**
   * Creates a new Color specified using red, green, blue, and alpha values
   * that are in the range of 0 to 255, converting them internally to a range of 0.0 to 1.0.
   *
   * @param {number} [red=255] The red component.
   * @param {number} [green=255] The green component.
   * @param {number} [blue=255] The blue component.
   * @param {number} [alpha=255] The alpha component.
   * @param {Color} [result] The object onto which to store the result.
   * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
   */
  public static fromBytes(
    red: number,
    green: number,
    blue: number,
    alpha: number,
    result: Color,
  ): Color {
    red = Color.byteToFloat(red ?? 255.0)
    green = Color.byteToFloat(green ?? 255.0)
    blue = Color.byteToFloat(blue ?? 255.0)
    alpha = Color.byteToFloat(alpha ?? 255.0)

    if (!defined(result)) {
      return new Color(red, green, blue, alpha)
    }

    result.red = red
    result.green = green
    result.blue = blue
    result.alpha = alpha
    return result
  }

  /**
   * Creates a new Color that has the same red, green, and blue components
   * of the specified color, but with the specified alpha value.
   *
   * @param {Color} color The base color
   * @param {number} alpha The new alpha component.
   * @param {Color} [result] The object onto which to store the result.
   * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
   *
   * @example const translucentRed = Color.fromAlpha(Color.RED, 0.9);
   */
  public static fromAlpha(color: Color, alpha: number, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('color', color)
    Check.typeOf.number('alpha', alpha)
    //>>includeEnd('debug');

    if (!defined(result)) {
      return new Color(color.red, color.green, color.blue, alpha)
    }

    result.red = color.red
    result.green = color.green
    result.blue = color.blue
    result.alpha = alpha
    return result
  }
  /**
   * Creates a new Color from a single numeric unsigned 32-bit RGBA value, using the endianness
   * of the system.
   *
   * @param {number} rgba A single numeric unsigned 32-bit RGBA value.
   * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
   * @returns {Color} The color object.
   *
   * @example
   * const color = Color.fromRgba(0x67ADDFFF);
   *
   * @see Color#toRgba
   */
  public static fromRgba(rgba: number, result: Color): Color {
    // scratchUint32Array and scratchUint8Array share an underlying array buffer
    scratchUint32Array[0] = rgba
    return Color.fromBytes(
      scratchUint8Array[0],
      scratchUint8Array[1],
      scratchUint8Array[2],
      scratchUint8Array[3],
      result,
    )
  }

  /**
   * Creates a Color instance from hue, saturation, and lightness.
   *
   * @param {number} [hue=0] The hue angle 0...1
   * @param {number} [saturation=0] The saturation value 0...1
   * @param {number} [lightness=0] The lightness value 0...1
   * @param {number} [alpha=1.0] The alpha component 0...1
   * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
   * @returns {Color} The color object.
   *
   * @see {@link http://www.w3.org/TR/css3-color/#hsl-color|CSS color values}
   */
  public static fromHsl(
    hue: number,
    saturation: number,
    lightness: number,
    alpha: number,
    result: Color,
  ): Color {
    hue = (hue ?? 0.0) % 1.0
    saturation = saturation ?? 0.0
    lightness = lightness ?? 0.0
    alpha = alpha ?? 1.0

    let red = lightness
    let green = lightness
    let blue = lightness

    if (saturation !== 0) {
      let m2
      if (lightness < 0.5) {
        m2 = lightness * (1 + saturation)
      } else {
        m2 = lightness + saturation - lightness * saturation
      }

      const m1 = 2.0 * lightness - m2
      red = hue2rgb(m1, m2, hue + 1 / 3)
      green = hue2rgb(m1, m2, hue)
      blue = hue2rgb(m1, m2, hue - 1 / 3)
    }

    if (!defined(result)) {
      return new Color(red, green, blue, alpha)
    }

    result.red = red
    result.green = green
    result.blue = blue
    result.alpha = alpha
    return result
  }

  /**
   * Creates a random color using the provided options. For reproducible random colors, you should
   * call {@link CesiumMath#setRandomNumberSeed} once at the beginning of your application.
   *
   * @param {object} [options] Object with the following properties:
   * @param {number} [options.red] If specified, the red component to use instead of a randomized value.
   * @param {number} [options.minimumRed=0.0] The maximum red value to generate if none was specified.
   * @param {number} [options.maximumRed=1.0] The minimum red value to generate if none was specified.
   * @param {number} [options.green] If specified, the green component to use instead of a randomized value.
   * @param {number} [options.minimumGreen=0.0] The maximum green value to generate if none was specified.
   * @param {number} [options.maximumGreen=1.0] The minimum green value to generate if none was specified.
   * @param {number} [options.blue] If specified, the blue component to use instead of a randomized value.
   * @param {number} [options.minimumBlue=0.0] The maximum blue value to generate if none was specified.
   * @param {number} [options.maximumBlue=1.0] The minimum blue value to generate if none was specified.
   * @param {number} [options.alpha] If specified, the alpha component to use instead of a randomized value.
   * @param {number} [options.minimumAlpha=0.0] The maximum alpha value to generate if none was specified.
   * @param {number} [options.maximumAlpha=1.0] The minimum alpha value to generate if none was specified.
   * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
   * @returns {Color} The modified result parameter or a new instance if result was undefined.
   *
   * @exception {DeveloperError} minimumRed must be less than or equal to maximumRed.
   * @exception {DeveloperError} minimumGreen must be less than or equal to maximumGreen.
   * @exception {DeveloperError} minimumBlue must be less than or equal to maximumBlue.
   * @exception {DeveloperError} minimumAlpha must be less than or equal to maximumAlpha.
   *
   * @example
   * //Create a completely random color
   * const color = Color.fromRandom();
   *
   * //Create a random shade of yellow.
   * const color1 = Color.fromRandom({
   *     red : 1.0,
   *     green : 1.0,
   *     alpha : 1.0
   * });
   *
   * //Create a random bright color.
   * const color2 = Color.fromRandom({
   *     minimumRed : 0.75,
   *     minimumGreen : 0.75,
   *     minimumBlue : 0.75,
   *     alpha : 1.0
   * });
   */
  public static fromRandom(
    options: {
      minimumRed?: number
      maximumRed?: number
      minimumGreen?: number
      maximumGreen?: number
      minimumBlue?: number
      maximumBlue?: number
      minimumAlpha?: number
      maximumAlpha?: number
      red?: number
      green?: number
      blue?: number
      alpha?: number
    },
    result: Color,
  ): Color {
    options = options ?? Frozen.EMPTY_OBJECT

    let red = options.red
    if (!defined(red)) {
      const minimumRed = options.minimumRed ?? 0
      const maximumRed = options.maximumRed ?? 1.0

      //>>includeStart('debug', pragmas.debug);
      Check.typeOf.tnumber.lessThanOrEquals('minimumRed', minimumRed, maximumRed)
      //>>includeEnd('debug');

      red = minimumRed + HYXHMathUtil.nextRandomNumber() * (maximumRed - minimumRed)
    }

    let green = options.green
    if (!defined(green)) {
      const minimumGreen = options.minimumGreen ?? 0
      const maximumGreen = options.maximumGreen ?? 1.0

      //>>includeStart('debug', pragmas.debug);
      Check.typeOf.tnumber.lessThanOrEquals('minimumGreen', minimumGreen, maximumGreen)
      //>>includeEnd('debug');
      green = minimumGreen + HYXHMathUtil.nextRandomNumber() * (maximumGreen - minimumGreen)
    }

    let blue = options.blue
    if (!defined(blue)) {
      const minimumBlue = options.minimumBlue ?? 0
      const maximumBlue = options.maximumBlue ?? 1.0

      //>>includeStart('debug', pragmas.debug);
      Check.typeOf.tnumber.lessThanOrEquals('minimumBlue', minimumBlue, maximumBlue)
      //>>includeEnd('debug');

      blue = minimumBlue + HYXHMathUtil.nextRandomNumber() * (maximumBlue - minimumBlue)
    }

    let alpha = options.alpha
    if (!defined(alpha)) {
      const minimumAlpha = options.minimumAlpha ?? 0
      const maximumAlpha = options.maximumAlpha ?? 1.0

      //>>includeStart('debug', pragmas.debug);
      Check.typeOf.tnumber.lessThanOrEquals('minimumAlpha', minimumAlpha, maximumAlpha)
      //>>includeEnd('debug');

      alpha = minimumAlpha + HYXHMathUtil.nextRandomNumber() * (maximumAlpha - minimumAlpha)
    }

    if (!defined(result)) {
      return new Color(red, green, blue, alpha)
    }

    result.red = defaultValue<number>(red, 0)
    result.green = defaultValue<number>(green, 0)
    result.blue = defaultValue<number>(blue, 0)
    result.alpha = defaultValue<number>(alpha, 0)
    return result
  }

  /**
   * Creates a Color instance from a CSS color value.
   *
   * @param {string} color The CSS color value in #rgb, #rgba, #rrggbb, #rrggbbaa, rgb(), rgba(), hsl(), or hsla() format.
   * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
   * @returns {Color} The color object, or undefined if the string was not a valid CSS color.
   *
   *
   * @example
   * const cesiumBlue = Color.fromCssColorString('#67ADDF');
   * const green = Color.fromCssColorString('green');
   *
   * @see 
   */
  public static fromCssColorString(color: string, result?: Color): Color | undefined {
    Check.typeOf.string('color', color)
    console.log("output:" + color);
    color = color.trim();
    result = result?? new Color()
   
    console.log("output:" + color);
    let matches = color.match(rgbaMatcher);//.exec(color) 在cocos 下支持此模式
   
    console.log("output2:" + matches);
    if (matches !== null) {
      defaultValue<Color>(result, new Color()).red = parseInt(matches[1], 16) / 15
      defaultValue<Color>(result, new Color()).green = parseInt(matches[2], 16) / 15.0
      defaultValue<Color>(result, new Color()).blue = parseInt(matches[3], 16) / 15.0
      defaultValue<Color>(result, new Color()).alpha = parseInt(matches[4] ?? 'f', 16) / 15.0
      return result
    }

    matches = color.match(rrggbbaaMatcher);           //.exec(color)
    if (matches !== null) {
      defaultValue<Color>(result, new Color()).red = parseInt(matches[1], 16) / 255.0
      defaultValue<Color>(result, new Color()).green = parseInt(matches[2], 16) / 255.0
      defaultValue<Color>(result, new Color()).blue = parseInt(matches[3], 16) / 255.0
      defaultValue<Color>(result, new Color()).alpha = parseInt(matches[4] ?? 'ff', 16) / 255.0
      return result
    }

    matches = color.match(rgbParenthesesMatcher);        //.exec(color)
    if (matches !== null) {
      defaultValue<Color>(result, new Color()).red =
        parseFloat(matches[1]) / ('%' === matches[1].substr(-1) ? 100.0 : 255.0)
      defaultValue<Color>(result, new Color()).green =
        parseFloat(matches[2]) / ('%' === matches[2].substr(-1) ? 100.0 : 255.0)
      defaultValue<Color>(result, new Color()).blue =
        parseFloat(matches[3]) / ('%' === matches[3].substr(-1) ? 100.0 : 255.0)
      defaultValue<Color>(result, new Color()).alpha = parseFloat(matches[4] ?? '1.0')
      return result
    }

    //matches = hslParenthesesMatcher.exec(color)
    matches = color.match(hslParenthesesMatcher);           //.exec(color)
    if (matches !== null) {
      return Color.fromHsl(
        parseFloat(matches[1]) / 360.0,
        parseFloat(matches[2]) / 100.0,
        parseFloat(matches[3]) / 100.0,
        parseFloat(matches[4] ?? '1.0'),
        defaultValue<Color>(result, new Color()),
      )
    }

    result = undefined
    return result
  }

  /**
   * The number of elements used to pack the object into an array.
   * @type {number}
   */
  public static readonly packedLength = 4

  /**
   * Stores the provided instance into the provided array.
   *
   * @param {Color} value The value to pack.
   * @param {number[]} array The array to pack into.
   * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
   *
   * @returns {number[]} The array that was packed into
   */
  public static pack(
    value: Color,
    array: UNION_NUMBER_ARRAY,
    startingIndex: number = 0): UNION_NUMBER_ARRAY | undefined {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('value', value)
    Check.defined('array', array)
    //>>includeEnd('debug');

    startingIndex = startingIndex ?? 0
    array[startingIndex++] = value.red
    array[startingIndex++] = value.green
    array[startingIndex++] = value.blue
    array[startingIndex] = value.alpha

    return array
  }

  /**
   * Retrieves an instance from a packed array.
   *
   * @param {number[]} array The packed array.
   * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
   * @param {Color} [result] The object into which to store the result.
   * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
   */
  public static unpack(
    array: UNION_NUMBER_ARRAY,
    startingIndex: number,
    result?: Color): Color | undefined {
    //>>includeStart('debug', pragmas.debug);
    Check.defined('array', array)
    //>>includeEnd('debug');

    startingIndex = startingIndex ?? 0
    if (!defined(result)) {
      result = new Color()
    }
    result!.red = array[startingIndex++]
    result!.green = array[startingIndex++]
    result!.blue = array[startingIndex++]
    result!.alpha = array[startingIndex]
    return result
  }

  /**
   * Converts a 'byte' color component in the range of 0 to 255 into
   * a 'float' color component in the range of 0 to 1.0.
   *
   * @param {number} number The number to be converted.
   * @returns {number} The converted number.
   */
  public static byteToFloat(number: number): number {
    return number / 255.0
  }

  /**
   * Converts a 'float' color component in the range of 0 to 1.0 into
   * a 'byte' color component in the range of 0 to 255.
   *
   * @param {number} number The number to be converted.
   * @returns {number} The converted number.
   */
  public static floatToByte(number: number): number {
    return number === 1.0 ? 255.0 : (number * 256.0) | 0
  }

  /**
   * Duplicates a Color.
   *
   * @param {Color} color The Color to duplicate.
   * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
   * @returns {Color} The modified result parameter or a new instance if result was undefined. (Returns undefined if color is undefined)
   */
  public static clone(color: Color, result?: Color): Color | undefined {
    if (!defined(color)) {
      return undefined
    }
    if (!defined(result)) {
      return new Color(color.red, color.green, color.blue, color.alpha)
    }
    result!.red = color.red
    result!.green = color.green
    result!.blue = color.blue
    result!.alpha = color.alpha
    return result
  }

  /**
   * Returns true if the first Color equals the second color.
   *
   * @param {Color} [left] The first Color to compare for equality.
   * @param {Color} [right] The second Color to compare for equality.
   * @returns {boolean} <code>true</code> if the Colors are equal; otherwise, <code>false</code>.
   */
  public static equals(left: Color, right: Color) {
    return (
      left === right || //
      (defined(left) && //
        defined(right) && //
        left.red === right.red && //
        left.green === right.green && //
        left.blue === right.blue && //
        left.alpha === right.alpha)
    )
  }

  /**
   * @private
   */
  public static equalsArray(color: Color, array: Array<number>, offset: number = 0): boolean {
    return (
      color.red === array[offset] &&
      color.green === array[offset + 1] &&
      color.blue === array[offset + 2] &&
      color.alpha === array[offset + 3]
    )
  }

  /**
   * Returns a duplicate of a Color instance.
   *
   * @param {Color} [result] The object to store the result in, if undefined a new instance will be created.
   * @returns {Color} The modified result parameter or a new instance if result was undefined.
   */
  public clone(result: Color): Color | undefined {
    return Color.clone(this, result)
  }

  /**
   * Returns true if this Color equals other.
   *
   * @param {Color} [other] The Color to compare for equality.
   * @returns {boolean} <code>true</code> if the Colors are equal; otherwise, <code>false</code>.
   */
  public equals(other: Color): boolean {
    return Color.equals(this, other)
  }

  /**
   * Returns <code>true</code> if this Color equals other componentwise within the specified epsilon.
   *
   * @param {Color} other The Color to compare for equality.
   * @param {number} [epsilon=0.0] The epsilon to use for equality testing.
   * @returns {boolean} <code>true</code> if the Colors are equal within the specified epsilon; otherwise, <code>false</code>.
   */
  public equalsEpsilon(other: Color, epsilon: number): boolean {
    return (
      this === other || //
      (defined(other) && //
        Math.abs(this.red - other.red) <= epsilon && //
        Math.abs(this.green - other.green) <= epsilon && //
        Math.abs(this.blue - other.blue) <= epsilon && //
        Math.abs(this.alpha - other.alpha) <= epsilon)
    )
  }

  /**
   * Creates a string representing this Color in the format '(red, green, blue, alpha)'.
   *
   * @returns {string} A string representing this Color in the format '(red, green, blue, alpha)'.
   */
  public toString(): string {
    return `(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`
  }

  /**
   * Creates a string containing the CSS color value for this color.
   *
   * @returns {string} The CSS equivalent of this color.
   *
   * @see {@link http://www.w3.org/TR/css3-color/#rgba-color|CSS RGB or RGBA color values}
   */
  public toCssColorString(): string {
    const red = Color.floatToByte(this.red)
    const green = Color.floatToByte(this.green)
    const blue = Color.floatToByte(this.blue)
    if (this.alpha === 1) {
      return `rgb(${red},${green},${blue})`
    }
    return `rgba(${red},${green},${blue},${this.alpha})`
  }

  /**
   * Creates a string containing CSS hex string color value for this color.
   *
   * @returns {string} The CSS hex string equivalent of this color.
   */
  public toCssHexString(): string {
    let r = Color.floatToByte(this.red).toString(16)
    if (r.length < 2) {
      r = `0${r}`
    }
    let g = Color.floatToByte(this.green).toString(16)
    if (g.length < 2) {
      g = `0${g}`
    }
    let b = Color.floatToByte(this.blue).toString(16)
    if (b.length < 2) {
      b = `0${b}`
    }
    if (this.alpha < 1) {
      let hexAlpha = Color.floatToByte(this.alpha).toString(16)
      if (hexAlpha.length < 2) {
        hexAlpha = `0${hexAlpha}`
      }
      return `#${r}${g}${b}${hexAlpha}`
    }
    return `#${r}${g}${b}`
  }

  /**
   * Converts this color to an array of red, green, blue, and alpha values
   * that are in the range of 0 to 255.
   *
   * @param {number[]} [result] The array to store the result in, if undefined a new instance will be created.
   * @returns {number[]} The modified result parameter or a new instance if result was undefined.
   */
  public toBytes(result: Array<number>): Array<number> {
    const red = Color.floatToByte(this.red)
    const green = Color.floatToByte(this.green)
    const blue = Color.floatToByte(this.blue)
    const alpha = Color.floatToByte(this.alpha)

    if (!defined(result)) {
      return [red, green, blue, alpha]
    }
    result[0] = red
    result[1] = green
    result[2] = blue
    result[3] = alpha
    return result
  }

  /**
   * Converts this color to a single numeric unsigned 32-bit RGBA value, using the endianness
   * of the system.
   *
   * @returns {number} A single numeric unsigned 32-bit RGBA value.
   *
   *
   * @example
   * const rgba = Color.BLUE.toRgba();
   *
   * @see Color.fromRgba
   */
  public toRgba(): number {
    // scratchUint32Array and scratchUint8Array share an underlying array buffer
    scratchUint8Array[0] = Color.floatToByte(this.red)
    scratchUint8Array[1] = Color.floatToByte(this.green)
    scratchUint8Array[2] = Color.floatToByte(this.blue)
    scratchUint8Array[3] = Color.floatToByte(this.alpha)
    return scratchUint32Array[0]
  }

  /**
   * Brightens this color by the provided magnitude.
   *
   * @param {number} magnitude A positive number indicating the amount to brighten.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   *
   * @example
   * const brightBlue = Color.BLUE.brighten(0.5, new Color());
   */
  public brighten(magnitude: number, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.number('magnitude', magnitude)
    Check.typeOf.tnumber.greaterThanOrEquals('magnitude', magnitude, 0.0)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    magnitude = 1.0 - magnitude
    result.red = 1.0 - (1.0 - this.red) * magnitude
    result.green = 1.0 - (1.0 - this.green) * magnitude
    result.blue = 1.0 - (1.0 - this.blue) * magnitude
    result.alpha = this.alpha
    return result
  }

  /**
   * Darkens this color by the provided magnitude.
   *
   * @param {number} magnitude A positive number indicating the amount to darken.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   *
   * @example
   * const darkBlue = Color.BLUE.darken(0.5, new Color());
   */
  public darken(magnitude: number, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.number('magnitude', magnitude)
    Check.typeOf.tnumber.greaterThanOrEquals('magnitude', magnitude, 0.0)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    magnitude = 1.0 - magnitude
    result.red = this.red * magnitude
    result.green = this.green * magnitude
    result.blue = this.blue * magnitude
    result.alpha = this.alpha
    return result
  }

  /**
   * Creates a new Color that has the same red, green, and blue components
   * as this Color, but with the specified alpha value.
   *
   * @param {number} alpha The new alpha component.
   * @param {Color} [result] The object onto which to store the result.
   * @returns {Color} The modified result parameter or a new Color instance if one was not provided.
   *
   * @example const translucentRed = Color.RED.withAlpha(0.9);
   */
  public withAlpha(alpha: number, result: Color): Color {
    return Color.fromAlpha(this, alpha, result)
  }

  /**
   * Computes the componentwise sum of two Colors.
   *
   * @param {Color} left The first Color.
   * @param {Color} right The second Color.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   */
  public static add(left: Color, right: Color, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('left', left)
    Check.typeOf.object('right', right)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    result.red = left.red + right.red
    result.green = left.green + right.green
    result.blue = left.blue + right.blue
    result.alpha = left.alpha + right.alpha
    return result
  }

  /**
   * Computes the componentwise difference of two Colors.
   *
   * @param {Color} left The first Color.
   * @param {Color} right The second Color.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   */
  public static subtract(left: Color, right: Color, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('left', left)
    Check.typeOf.object('right', right)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    result.red = left.red - right.red
    result.green = left.green - right.green
    result.blue = left.blue - right.blue
    result.alpha = left.alpha - right.alpha
    return result
  }

  /**
   * Computes the componentwise product of two Colors.
   *
   * @param {Color} left The first Color.
   * @param {Color} right The second Color.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   */
  public static multiply(left: Color, right: Color, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('left', left)
    Check.typeOf.object('right', right)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    result.red = left.red * right.red
    result.green = left.green * right.green
    result.blue = left.blue * right.blue
    result.alpha = left.alpha * right.alpha
    return result
  }

  /**
   * Computes the componentwise quotient of two Colors.
   *
   * @param {Color} left The first Color.
   * @param {Color} right The second Color.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   */
  public static divide(left: Color, right: Color, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('left', left)
    Check.typeOf.object('right', right)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    result.red = left.red / right.red
    result.green = left.green / right.green
    result.blue = left.blue / right.blue
    result.alpha = left.alpha / right.alpha
    return result
  }

  /**
   * Computes the componentwise modulus of two Colors.
   *
   * @param {Color} left The first Color.
   * @param {Color} right The second Color.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   */
  public static mod(left: Color, right: Color, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('left', left)
    Check.typeOf.object('right', right)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    result.red = left.red % right.red
    result.green = left.green % right.green
    result.blue = left.blue % right.blue
    result.alpha = left.alpha % right.alpha
    return result
  }

  /**
   * Computes the linear interpolation or extrapolation at t between the provided colors.
   *
   * @param {Color} start The color corresponding to t at 0.0.
   * @param {Color} end The color corresponding to t at 1.0.
   * @param {number} t The point along t at which to interpolate.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   */
  public static lerp(start: Color, end: Color, t: number, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('start', start)
    Check.typeOf.object('end', end)
    Check.typeOf.number('t', t)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    result.red = HYXHMathUtil.lerp(start.red, end.red, t)
    result.green = HYXHMathUtil.lerp(start.green, end.green, t)
    result.blue = HYXHMathUtil.lerp(start.blue, end.blue, t)
    result.alpha = HYXHMathUtil.lerp(start.alpha, end.alpha, t)
    return result
  }

  /**
   * Multiplies the provided Color componentwise by the provided scalar.
   *
   * @param {Color} color The Color to be scaled.
   * @param {number} scalar The scalar to multiply with.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   */
  public static multiplyByScalar(color: Color, scalar: number, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('color', color)
    Check.typeOf.number('scalar', scalar)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    result.red = color.red * scalar
    result.green = color.green * scalar
    result.blue = color.blue * scalar
    result.alpha = color.alpha * scalar
    return result
  }

  /**
   * Divides the provided Color componentwise by the provided scalar.
   *
   * @param {Color} color The Color to be divided.
   * @param {number} scalar The scalar to divide with.
   * @param {Color} result The object onto which to store the result.
   * @returns {Color} The modified result parameter.
   */
  public static divideByScalar(color: Color, scalar: number, result: Color): Color {
    //>>includeStart('debug', pragmas.debug);
    Check.typeOf.object('color', color)
    Check.typeOf.number('scalar', scalar)
    Check.typeOf.object('result', result)
    //>>includeEnd('debug');

    result.red = color.red / scalar
    result.green = color.green / scalar
    result.blue = color.blue / scalar
    result.alpha = color.alpha / scalar
    return result
  }
} // end class Color
let scratchArrayBuffer: ArrayBuffer = new ArrayBuffer(4)
let scratchUint32Array: Uint32Array = new Uint32Array(4)
let scratchUint8Array: Uint8Array = new Uint8Array(4)

/**
 * 默认颜色清单
 */
export const DefaultColorsList : IColorIndex = {
  
  
  /**
   * An immutable Color instance initialized to CSS color 
   * 
   */
  ALICEBLUE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#F0F8FF')),
     new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FAEBD7
   * <span class="colorSwath" style="background: #FAEBD7;"></span>
   *
   *  
   * @type {Color}
   */
  ANTIQUEWHITE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#FAEBD7')),
    new Color(), ),

  /**
   * An immutable Color instance initialized to CSS color #00FFFF
   * <span class="colorSwath" style="background: #00FFFF;"></span>
   *
   * @constant
   * @type {Color}
   */
  AQUA: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#00FFFF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #7FFFD4
   * <span class="colorSwath" style="background: #7FFFD4;"></span>
   *
   * @constant
   * @type {Color}
   */
  AQUAMARINE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#7FFFD4')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #F0FFFF
   * <span class="colorSwath" style="background: #F0FFFF;"></span>
   *
   * @constant
   * @type {Color}
   */
  AZURE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F0FFFF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #F5F5DC
   * <span class="colorSwath" style="background: #F5F5DC;"></span>
   *
   * @constant
   * @type {Color}
   */
  BEIGE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F5F5DC')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFE4C4
   * <span class="colorSwath" style="background: #FFE4C4;"></span>
   *
   * @constant
   * @type {Color}
   */
  BISQUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFE4C4')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #000000
   * <span class="colorSwath" style="background: #000000;"></span>
   *
   * @constant
   * @type {Color}
   */
  BLACK: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#000000')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFEBCD
   * <span class="colorSwath" style="background: #FFEBCD;"></span>
   *
   * @constant
   * @type {Color}
   */
  BLANCHEDALMOND: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#FFEBCD')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #0000FF
   * <span class="colorSwath" style="background: #0000FF;"></span>
   *
   * @constant
   * @type {Color}
   */
  BLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#0000FF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #8A2BE2
   * <span class="colorSwath" style="background: #8A2BE2;"></span>
   *
   * @constant
   * @type {Color}
   */
  BLUEVIOLET: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#8A2BE2')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #A52A2A
   * <span class="colorSwath" style="background: #A52A2A;"></span>
   *
   * @constant
   * @type {Color}
   */
  BROWN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#A52A2A')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #DEB887
   * <span class="colorSwath" style="background: #DEB887;"></span>
   *
   * @constant
   * @type {Color}
   */
  BURLYWOOD: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#DEB887')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #5F9EA0
   * <span class="colorSwath" style="background: #5F9EA0;"></span>
   *
   * @constant
   * @type {Color}
   */
  CADETBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#5F9EA0')), new Color()),
  /**
   * An immutable Color instance initialized to CSS color #7FFF00
   * <span class="colorSwath" style="background: #7FFF00;"></span>
   *
   * @constant
   * @type {Color}
   */
  CHARTREUSE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#7FFF00')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #D2691E
   * <span class="colorSwath" style="background: #D2691E;"></span>
   *
   * @constant
   * @type {Color}
   */
  CHOCOLATE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#D2691E')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FF7F50
   * <span class="colorSwath" style="background: #FF7F50;"></span>
   *
   * @constant
   * @type {Color}
   */
  CORAL: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FF7F50')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #6495ED
   * <span class="colorSwath" style="background: #6495ED;"></span>
   *
   * @constant
   * @type {Color}
   */
  CORNFLOWERBLUE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#6495ED')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #FFF8DC
   * <span class="colorSwath" style="background: #FFF8DC;"></span>
   *
   * @constant
   * @type {Color}
   */
  CORNSILK: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFF8DC')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #DC143C
   * <span class="colorSwath" style="background: #DC143C;"></span>
   *
   * @constant
   * @type {Color}
   */
  CRIMSON: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#DC143C')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #00FFFF
   * <span class="colorSwath" style="background: #00FFFF;"></span>
   *
   * @constant
   * @type {Color}
   */
  CYAN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#00FFFF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #00008B
   * <span class="colorSwath" style="background: #00008B;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#00008B')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #008B8B
   * <span class="colorSwath" style="background: #008B8B;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKCYAN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#008B8B')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #B8860B
   * <span class="colorSwath" style="background: #B8860B;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKGOLDENROD: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#B8860B')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #A9A9A9
   * <span class="colorSwath" style="background: #A9A9A9;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKGRAY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#A9A9A9')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #006400
   * <span class="colorSwath" style="background: #006400;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKGREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#006400')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #A9A9A9
   * <span class="colorSwath" style="background: #A9A9A9;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKGREY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#A9A9A9')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #BDB76B
   * <span class="colorSwath" style="background: #BDB76B;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKKHAKI: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#BDB76B')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #8B008B
   * <span class="colorSwath" style="background: #8B008B;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKMAGENTA: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#8B008B')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #556B2F
   * <span class="colorSwath" style="background: #556B2F;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKOLIVEGREEN: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#556B2F')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #FF8C00
   * <span class="colorSwath" style="background: #FF8C00;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKORANGE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FF8C00')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #9932CC
   * <span class="colorSwath" style="background: #9932CC;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKORCHID: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#9932CC')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #8B0000
   * <span class="colorSwath" style="background: #8B0000;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKRED: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#8B0000')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #E9967A
   * <span class="colorSwath" style="background: #E9967A;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKSALMON: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#E9967A')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #8FBC8F
   * <span class="colorSwath" style="background: #8FBC8F;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKSEAGREEN: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#8FBC8F')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #483D8B
   * <span class="colorSwath" style="background: #483D8B;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKSLATEBLUE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#483D8B')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #2F4F4F
   * <span class="colorSwath" style="background: #2F4F4F;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKSLATEGRAY: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#2F4F4F')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #2F4F4F
   * <span class="colorSwath" style="background: #2F4F4F;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKSLATEGREY: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#2F4F4F')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #00CED1
   * <span class="colorSwath" style="background: #00CED1;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKTURQUOISE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#00CED1')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #9400D3
   * <span class="colorSwath" style="background: #9400D3;"></span>
   *
   * @constant
   * @type {Color}
   */
  DARKVIOLET: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#9400D3')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FF1493
   * <span class="colorSwath" style="background: #FF1493;"></span>
   *
   * @constant
   * @type {Color}
   */
  DEEPPINK: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FF1493')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #00BFFF
   * <span class="colorSwath" style="background: #00BFFF;"></span>
   *
   * @constant
   * @type {Color}
   */
  DEEPSKYBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#00BFFF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #696969
   * <span class="colorSwath" style="background: #696969;"></span>
   *
   * @constant
   * @type {Color}
   */
  DIMGRAY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#696969')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #696969
   * <span class="colorSwath" style="background: #696969;"></span>
   *
   * @constant
   * @type {Color}
   */
  DIMGREY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#696969')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #1E90FF
   * <span class="colorSwath" style="background: #1E90FF;"></span>
   *
   * @constant
   * @type {Color}
   */
  DODGERBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#1E90FF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #B22222
   * <span class="colorSwath" style="background: #B22222;"></span>
   *
   * @constant
   * @type {Color}
   */
  FIREBRICK: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#B22222')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFFAF0
   * <span class="colorSwath" style="background: #FFFAF0;"></span>
   *
   * @constant
   * @type {Color}
   */
  FLORALWHITE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFFAF0')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #228B22
   * <span class="colorSwath" style="background: #228B22;"></span>
   *
   * @constant
   * @type {Color}
   */
  FORESTGREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#228B22')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FF00FF
   * <span class="colorSwath" style="background: #FF00FF;"></span>
   *
   * @constant
   * @type {Color}
   */
  FUCHSIA: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FF00FF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #DCDCDC
   * <span class="colorSwath" style="background: #DCDCDC;"></span>
   *
   * @constant
   * @type {Color}
   */
  GAINSBORO: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#DCDCDC')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #F8F8FF
   * <span class="colorSwath" style="background: #F8F8FF;"></span>
   *
   * @constant
   * @type {Color}
   */
  GHOSTWHITE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F8F8FF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFD700
   * <span class="colorSwath" style="background: #FFD700;"></span>
   *
   * @constant
   * @type {Color}
   */
  GOLD: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFD700')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #DAA520
   * <span class="colorSwath" style="background: #DAA520;"></span>
   *
   * @constant
   * @type {Color}
   */
  GOLDENROD: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#DAA520')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #808080
   * <span class="colorSwath" style="background: #808080;"></span>
   *
   * @constant
   * @type {Color}
   */
  GRAY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#808080')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #008000
   * <span class="colorSwath" style="background: #008000;"></span>
   *
   * @constant
   * @type {Color}
   */
  GREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#008000')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #ADFF2F
   * <span class="colorSwath" style="background: #ADFF2F;"></span>
   *
   * @constant
   * @type {Color}
   */
  GREENYELLOW: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#ADFF2F')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #808080
   * <span class="colorSwath" style="background: #808080;"></span>
   *
   * @constant
   * @type {Color}
   */
  //GREY = Color.GRAY
  GREY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#808080')), new Color()),
  /**
   * An immutable Color instance initialized to CSS color #F0FFF0
   * <span class="colorSwath" style="background: #F0FFF0;"></span>
   *
   * @constant
   * @type {Color}
   */
  HONEYDEW: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F0FFF0')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FF69B4
   * <span class="colorSwath" style="background: #FF69B4;"></span>
   *
   * @constant
   * @type {Color}
   */
  HOTPINK: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FF69B4')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #CD5C5C
   * <span class="colorSwath" style="background: #CD5C5C;"></span>
   *
   * @constant
   * @type {Color}
   */
  INDIANRED: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#CD5C5C')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #4B0082
   * <span class="colorSwath" style="background: #4B0082;"></span>
   *
   * @constant
   * @type {Color}
   */
  INDIGO: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#4B0082')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFFFF0
   * <span class="colorSwath" style="background: #FFFFF0;"></span>
   *
   * @constant
   * @type {Color}
   */
  IVORY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFFFF0')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #F0E68C
   * <span class="colorSwath" style="background: #F0E68C;"></span>
   *
   * @constant
   * @type {Color}
   */
  KHAKI: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F0E68C')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #E6E6FA
   * <span class="colorSwath" style="background: #E6E6FA;"></span>
   *
   * @constant
   * @type {Color}
   */
  LAVENDER: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#E6E6FA')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFF0F5
   * <span class="colorSwath" style="background: #FFF0F5;"></span>
   *
   * @constant
   * @type {Color}
   */
  LAVENDAR_BLUSH: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#FFF0F5')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #7CFC00
   * <span class="colorSwath" style="background: #7CFC00;"></span>
   *
   * @constant
   * @type {Color}
   */
  LAWNGREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#7CFC00')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFFACD
   * <span class="colorSwath" style="background: #FFFACD;"></span>
   *
   * @constant
   * @type {Color}
   */
  LEMONCHIFFON: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#FFFACD')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #ADD8E6
   * <span class="colorSwath" style="background: #ADD8E6;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#ADD8E6')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #F08080
   * <span class="colorSwath" style="background: #F08080;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTCORAL: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F08080')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #E0FFFF
   * <span class="colorSwath" style="background: #E0FFFF;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTCYAN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#E0FFFF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FAFAD2
   * <span class="colorSwath" style="background: #FAFAD2;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTGOLDENRODYELLOW: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#FAFAD2')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #D3D3D3
   * <span class="colorSwath" style="background: #D3D3D3;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTGRAY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#D3D3D3')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #90EE90
   * <span class="colorSwath" style="background: #90EE90;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTGREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#90EE90')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #D3D3D3
   * <span class="colorSwath" style="background: #D3D3D3;"></span>
   *
   * @constant
   * @type {Color}
   */
  //LIGHTGREY = Color.LIGHTGRAY
  LIGHTGREY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#D3D3D3')), new Color()),
  /**
   * An immutable Color instance initialized to CSS color #FFB6C1
   * <span class="colorSwath" style="background: #FFB6C1;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTPINK: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFB6C1')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #20B2AA
   * <span class="colorSwath" style="background: #20B2AA;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTSEAGREEN: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#20B2AA')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #87CEFA
   * <span class="colorSwath" style="background: #87CEFA;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTSKYBLUE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#87CEFA')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #778899
   * <span class="colorSwath" style="background: #778899;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTSLATEGRAY: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#778899')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #778899
   * <span class="colorSwath" style="background: #778899;"></span>
   *
   * @constant
   * @type {Color}
   */
  //LIGHTSLATEGREY = Color.LIGHTSLATEGRAY
  LIGHTSLATEGREY: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#778899')),
    new Color(),
  ),
  /**
   * An immutable Color instance initialized to CSS color #B0C4DE
   * <span class="colorSwath" style="background: #B0C4DE;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTSTEELBLUE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#B0C4DE')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #FFFFE0
   * <span class="colorSwath" style="background: #FFFFE0;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIGHTYELLOW: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFFFE0')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #00FF00
   * <span class="colorSwath" style="background: #00FF00;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIME: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#00FF00')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #32CD32
   * <span class="colorSwath" style="background: #32CD32;"></span>
   *
   * @constant
   * @type {Color}
   */
  LIMEGREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#32CD32')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FAF0E6
   * <span class="colorSwath" style="background: #FAF0E6;"></span>
   *
   * @constant
   * @type {Color}
   */
  LINEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FAF0E6')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FF00FF
   * <span class="colorSwath" style="background: #FF00FF;"></span>
   *
   * @constant
   * @type {Color}
   */
  MAGENTA: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FF00FF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #800000
   * <span class="colorSwath" style="background: #800000;"></span>
   *
   * @constant
   * @type {Color}
   */
  MAROON: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#800000')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #66CDAA
   * <span class="colorSwath" style="background: #66CDAA;"></span>
   *
   * @constant
   * @type {Color}
   */
  MEDIUMAQUAMARINE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#66CDAA')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #0000CD
   * <span class="colorSwath" style="background: #0000CD;"></span>
   *
   * @constant
   * @type {Color}
   */
  MEDIUMBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#0000CD')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #BA55D3
   * <span class="colorSwath" style="background: #BA55D3;"></span>
   *
   * @constant
   * @type {Color}
   */
  MEDIUMORCHID: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#BA55D3')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #9370DB
   * <span class="colorSwath" style="background: #9370DB;"></span>
   *
   * @constant
   * @type {Color}
   */
  MEDIUMPURPLE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#9370DB')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #3CB371
   * <span class="colorSwath" style="background: #3CB371;"></span>
   *
   * @constant
   * @type {Color}
   */
  MEDIUMSEAGREEN: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#3CB371')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #7B68EE
   * <span class="colorSwath" style="background: #7B68EE;"></span>
   *
   * @constant
   * @type {Color}
   */
  MEDIUMSLATEBLUE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#7B68EE')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #00FA9A
   * <span class="colorSwath" style="background: #00FA9A;"></span>
   *
   * @constant
   * @type {Color}
   */
  MEDIUMSPRINGGREEN: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#00FA9A')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #48D1CC
   * <span class="colorSwath" style="background: #48D1CC;"></span>
   *
   * @constant
   * @type {Color}
   */
  MEDIUMTURQUOISE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#48D1CC')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #C71585
   * <span class="colorSwath" style="background: #C71585;"></span>
   *
   * @constant
   * @type {Color}
   */
  MEDIUMVIOLETRED: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#C71585')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #191970
   * <span class="colorSwath" style="background: #191970;"></span>
   *
   * @constant
   * @type {Color}
   */
  MIDNIGHTBLUE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#191970')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #F5FFFA
   * <span class="colorSwath" style="background: #F5FFFA;"></span>
   *
   * @constant
   * @type {Color}
   */
  MINTCREAM: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F5FFFA')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFE4E1
   * <span class="colorSwath" style="background: #FFE4E1;"></span>
   *
   * @constant
   * @type {Color}
   */
  MISTYROSE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFE4E1')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFE4B5
   * <span class="colorSwath" style="background: #FFE4B5;"></span>
   *
   * @constant
   * @type {Color}
   */
  MOCCASIN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFE4B5')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFDEAD
   * <span class="colorSwath" style="background: #FFDEAD;"></span>
   *
   * @constant
   * @type {Color}
   */
  NAVAJOWHITE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFDEAD')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #000080
   * <span class="colorSwath" style="background: #000080;"></span>
   *
   * @constant
   * @type {Color}
   */
  NAVY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#000080')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FDF5E6
   * <span class="colorSwath" style="background: #FDF5E6;"></span>
   *
   * @constant
   * @type {Color}
   */
  OLDLACE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FDF5E6')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #808000
   * <span class="colorSwath" style="background: #808000;"></span>
   *
   * @constant
   * @type {Color}
   */
  OLIVE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#808000')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #6B8E23
   * <span class="colorSwath" style="background: #6B8E23;"></span>
   *
   * @constant
   * @type {Color}
   */
  OLIVEDRAB: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#6B8E23')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFA500
   * <span class="colorSwath" style="background: #FFA500;"></span>
   *
   * @constant
   * @type {Color}
   */
  ORANGE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFA500')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FF4500
   * <span class="colorSwath" style="background: #FF4500;"></span>
   *
   * @constant
   * @type {Color}
   */
  ORANGERED: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FF4500')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #DA70D6
   * <span class="colorSwath" style="background: #DA70D6;"></span>
   *
   * @constant
   * @type {Color}
   */
  ORCHID: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#DA70D6')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #EEE8AA
   * <span class="colorSwath" style="background: #EEE8AA;"></span>
   *
   * @constant
   * @type {Color}
   */
  PALEGOLDENROD: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#EEE8AA')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #98FB98
   * <span class="colorSwath" style="background: #98FB98;"></span>
   *
   * @constant
   * @type {Color}
   */
  PALEGREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#98FB98')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #AFEEEE
   * <span class="colorSwath" style="background: #AFEEEE;"></span>
   *
   * @constant
   * @type {Color}
   */
  PALETURQUOISE: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#AFEEEE')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #DB7093
   * <span class="colorSwath" style="background: #DB7093;"></span>
   *
   * @constant
   * @type {Color}
   */
  PALEVIOLETRED: defaultValue<Color>(
    Object.freeze(Color.fromCssColorString('#DB7093')),
    new Color(),
  ),

  /**
   * An immutable Color instance initialized to CSS color #FFEFD5
   * <span class="colorSwath" style="background: #FFEFD5;"></span>
   *
   * @constant
   * @type {Color}
   */
  PAPAYAWHIP: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFEFD5')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFDAB9
   * <span class="colorSwath" style="background: #FFDAB9;"></span>
   *
   * @constant
   * @type {Color}
   */
  PEACHPUFF: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFDAB9')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #CD853F
   * <span class="colorSwath" style="background: #CD853F;"></span>
   *
   * @constant
   * @type {Color}
   */
  PERU: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#CD853F')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFC0CB
   * <span class="colorSwath" style="background: #FFC0CB;"></span>
   *
   * @constant
   * @type {Color}
   */
  PINK: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFC0CB')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #DDA0DD
   * <span class="colorSwath" style="background: #DDA0DD;"></span>
   *
   * @constant
   * @type {Color}
   */
  PLUM: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#DDA0DD')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #B0E0E6
   * <span class="colorSwath" style="background: #B0E0E6;"></span>
   *
   * @constant
   * @type {Color}
   */
  POWDERBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#B0E0E6')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #800080
   * <span class="colorSwath" style="background: #800080;"></span>
   *
   * @constant
   * @type {Color}
   */
  PURPLE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#800080')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FF0000
   * <span class="colorSwath" style="background: #FF0000;"></span>
   *
   * @constant
   * @type {Color}
   */
  RED: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FF0000')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #BC8F8F
   * <span class="colorSwath" style="background: #BC8F8F;"></span>
   *
   * @constant
   * @type {Color}
   */
  ROSYBROWN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#BC8F8F')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #4169E1
   * <span class="colorSwath" style="background: #4169E1;"></span>
   *
   * @constant
   * @type {Color}
   */
  ROYALBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#4169E1')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #8B4513
   * <span class="colorSwath" style="background: #8B4513;"></span>
   *
   * @constant
   * @type {Color}
   */
  SADDLEBROWN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#8B4513')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FA8072
   * <span class="colorSwath" style="background: #FA8072;"></span>
   *
   * @constant
   * @type {Color}
   */
  SALMON: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FA8072')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #F4A460
   * <span class="colorSwath" style="background: #F4A460;"></span>
   *
   * @constant
   * @type {Color}
   */
  SANDYBROWN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F4A460')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #2E8B57
   * <span class="colorSwath" style="background: #2E8B57;"></span>
   *
   * @constant
   * @type {Color}
   */
  SEAGREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#2E8B57')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFF5EE
   * <span class="colorSwath" style="background: #FFF5EE;"></span>
   *
   * @constant
   * @type {Color}
   */
  SEASHELL: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFF5EE')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #A0522D
   * <span class="colorSwath" style="background: #A0522D;"></span>
   *
   * @constant
   * @type {Color}
   */
  SIENNA: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#A0522D')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #C0C0C0
   * <span class="colorSwath" style="background: #C0C0C0;"></span>
   *
   * @constant
   * @type {Color}
   */
  SILVER: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#C0C0C0')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #87CEEB
   * <span class="colorSwath" style="background: #87CEEB;"></span>
   *
   * @constant
   * @type {Color}
   */
  SKYBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#87CEEB')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #6A5ACD
   * <span class="colorSwath" style="background: #6A5ACD;"></span>
   *
   * @constant
   * @type {Color}
   */
  SLATEBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#6A5ACD')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #708090
   * <span class="colorSwath" style="background: #708090;"></span>
   *
   * @constant
   * @type {Color}
   */
  SLATEGRAY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#708090')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #708090
   * <span class="colorSwath" style="background: #708090;"></span>
   *
   * @constant
   * @type {Color}
   */
  //SLATEGREY = Color.SLATEGRAY
  SLATEGREY: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#708090')), new Color()),
  /**
   * An immutable Color instance initialized to CSS color #FFFAFA
   * <span class="colorSwath" style="background: #FFFAFA;"></span>
   *
   * @constant
   * @type {Color}
   */
  SNOW: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFFAFA')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #00FF7F
   * <span class="colorSwath" style="background: #00FF7F;"></span>
   *
   * @constant
   * @type {Color}
   */
  SPRINGGREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#00FF7F')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #4682B4
   * <span class="colorSwath" style="background: #4682B4;"></span>
   *
   * @constant
   * @type {Color}
   */
  STEELBLUE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#4682B4')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #D2B48C
   * <span class="colorSwath" style="background: #D2B48C;"></span>
   *
   * @constant
   * @type {Color}
   */
  TAN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#D2B48C')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #008080
   * <span class="colorSwath" style="background: #008080;"></span>
   *
   * @constant
   * @type {Color}
   */
  TEAL: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#008080')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #D8BFD8
   * <span class="colorSwath" style="background: #D8BFD8;"></span>
   *
   * @constant
   * @type {Color}
   */
  THISTLE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#D8BFD8')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FF6347
   * <span class="colorSwath" style="background: #FF6347;"></span>
   *
   * @constant
   * @type {Color}
   */
  TOMATO: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FF6347')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #40E0D0
   * <span class="colorSwath" style="background: #40E0D0;"></span>
   *
   * @constant
   * @type {Color}
   */
  TURQUOISE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#40E0D0')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #EE82EE
   * <span class="colorSwath" style="background: #EE82EE;"></span>
   *
   * @constant
   * @type {Color}
   */
  VIOLET: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#EE82EE')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #F5DEB3
   * <span class="colorSwath" style="background: #F5DEB3;"></span>
   *
   * @constant
   * @type {Color}
   */
  WHEAT: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F5DEB3')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFFFFF
   * <span class="colorSwath" style="background: #FFFFFF;"></span>
   *
   * @constant
   * @type {Color}
   */
  WHITE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFFFFF')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #F5F5F5
   * <span class="colorSwath" style="background: #F5F5F5;"></span>
   *
   * @constant
   * @type {Color}
   */
  WHITESMOKE: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#F5F5F5')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #FFFF00
   * <span class="colorSwath" style="background: #FFFF00;"></span>
   *
   * @constant
   * @type {Color}
   */
  YELLOW: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#FFFF00')), new Color()),

  /**
   * An immutable Color instance initialized to CSS color #9ACD32
   * <span class="colorSwath" style="background: #9ACD32;"></span>
   *
   * @constant
   * @type {Color}
   */
  YELLOWGREEN: defaultValue<Color>(Object.freeze(Color.fromCssColorString('#9ACD32')), new Color()),

  /**
   * An immutable Color instance initialized to CSS transparent.
   * <span class="colorSwath" style="background: transparent;"></span>
   *
   * @constant
   * @type {Color}
   */
  TRANSPARENT: Object.freeze(new Color(0, 0, 0, 0)),
}

//#rgba
const rgbaMatcher = /^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i
//#rrggbbaa
const rrggbbaaMatcher = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i
//rgb(), rgba(), or rgb%()
const rgbParenthesesMatcher =
  /^rgba?\s*\(\s*([0-9.]+%?)\s*[,\s]+\s*([0-9.]+%?)\s*[,\s]+\s*([0-9.]+%?)(?:\s*[,\s/]+\s*([0-9.]+))?\s*\)$/i
//hsl() or hsla()
const hslParenthesesMatcher =
  /^hsla?\s*\(\s*([0-9.]+)\s*[,\s]+\s*([0-9.]+%)\s*[,\s]+\s*([0-9.]+%)(?:\s*[,\s/]+\s*([0-9.]+))?\s*\)$/i
/**
 * Hue主要用来描述颜色的基本特征，即颜色的色调或色度, 将色调转换为RGB 颜射
 * 使用红色、绿色、蓝色和透明度值指定的颜色，
 * 范围从<code>0</code>（无强度）到<code>1.0</code>（全强度）。
 * @param {number} [m1=1.0] The red component.
 * @param {number} [m2=1.0] The green component.
 * @param {number} [h=1.0] The blue component.
 * @alias Color
 */
export function hue2rgb(m1: number, m2: number, h: number): number {
  if (h < 0) {
    h += 1
  }
  if (h > 1) {
    h -= 1
  }
  if (h * 6 < 1) {
    return m1 + (m2 - m1) * 6 * h
  }
  if (h * 2 < 1) {
    return m2
  }
  if (h * 3 < 2) {
    return m1 + (m2 - m1) * (2 / 3 - h) * 6
  }
  return m1
}
